home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr46 / vfwdk.zip / VFWSDK.ZIP / SAMPLES / MSRLEC / LIBINIT.ASM < prev    next >
Assembly Source File  |  1993-01-31  |  5KB  |  185 lines

  1.     page    ,132
  2. ;-----------------------------Module-Header-----------------------------;
  3. ; Module Name:  LIBINIT.ASM
  4. ;
  5. ; library stub to do local init for a Dynamic linked library
  6. ;
  7. ; Copyright (c) 1990-1993 Microsoft Corporation.  All Rights Reserved.
  8. ;
  9. ; You have a royalty-free right to use, modify, reproduce and 
  10. ; distribute the Sample Files (and/or any modified version) in 
  11. ; any way you find useful, provided that you agree that 
  12. ; Microsoft has no warranty obligations or liability for any 
  13. ; Sample Application Files.
  14. ;
  15. ;
  16. ; Restrictions:
  17. ;
  18. ;   This must be the first object file in the LINK line, this assures
  19. ;   that the reserved parameter block is at the *base* of DGROUP
  20. ;
  21. ;-----------------------------------------------------------------------;
  22.  
  23. ?PLM=1      ; PASCAL Calling convention is DEFAULT
  24. ?WIN=1        ; Windows calling convention
  25.  
  26.         .286
  27.     .xlist
  28.     include cmacros.inc
  29.         .list
  30.  
  31. ifndef SEGNAME
  32.     SEGNAME equ <_TEXT>
  33. endif
  34.  
  35. createSeg %SEGNAME, CodeSeg, word, public, CODE
  36.  
  37. ;-----------------------------------------------------------------------;
  38. ;
  39. ;   externs from KERNEL
  40. ;
  41.         externFP    <LocalInit>
  42. ifdef DEBUG
  43.         externFP    <FatalAppExit>
  44. endif
  45.  
  46. ;-----------------------------------------------------------------------;
  47. ;
  48. ;   LibMain is the function in C code we will call on a DLL load.
  49. ;   it is assumed in the same segment as we are.
  50. ;
  51.         externNP    <LibMain>
  52. ;;;;;;;;externFP    <LibMain>  ;; Use this line if LibMain is far call
  53.  
  54. ;-----------------------------------------------------------------------;
  55. ;
  56. ; Stuff needed to avoid the C runtime coming in, and init the windows
  57. ; reserved parameter block at the base of DGROUP
  58. ;
  59. sBegin  Data
  60. assumes DS,Data
  61.             org 0               ; base of DATA segment!
  62.  
  63.             DD  0               ; So null pointers get 0
  64. maxRsrvPtrs = 5
  65.             DW  maxRsrvPtrs
  66. usedRsrvPtrs = 0
  67. labelDP     <PUBLIC,rsrvptrs>
  68.  
  69. DefRsrvPtr  MACRO   name
  70. globalW     name,0
  71. usedRsrvPtrs = usedRsrvPtrs + 1
  72. ENDM
  73.  
  74. DefRsrvPtr  pLocalHeap          ; Local heap pointer
  75. DefRsrvPtr  pAtomTable          ; Atom table pointer
  76. DefRsrvPtr  pStackTop           ; top of stack
  77. DefRsrvPtr  pStackMin           ; minimum value of SP
  78. DefRsrvPtr  pStackBot           ; bottom of stack
  79.  
  80. if maxRsrvPtrs-usedRsrvPtrs
  81.             DW maxRsrvPtrs-usedRsrvPtrs DUP (0)
  82. endif
  83.  
  84. public  __acrtused
  85.     __acrtused = 1
  86.  
  87. sEnd        Data
  88.  
  89. ;-----------------------------------------------------------------------;
  90.  
  91. sBegin  CodeSeg
  92.         assumes cs,CodeSeg
  93.  
  94. ;--------------------------Private-Routine-----------------------------;
  95. ;
  96. ; LibEntry - called when DLL is loaded
  97. ;
  98. ; Entry:
  99. ;       CX    = size of heap
  100. ;       DI    = module handle
  101. ;       DS    = automatic data segment
  102. ;       ES:SI = address of command line (not used by a DLL)
  103. ;
  104. ; Returns:
  105. ;       AX = TRUE if success
  106. ; Error Returns:
  107. ;       AX = FALSE if error (ie fail load process)
  108. ; Registers Preserved:
  109. ;    SI,DI,DS,BP
  110. ; Registers Destroyed:
  111. ;       AX,BX,CX,DX,ES,FLAGS
  112. ; Calls:
  113. ;    None
  114. ;
  115. ;-----------------------------------------------------------------------;
  116.         assumes ds,Data
  117.         assumes es,nothing
  118.  
  119. cProc   LibEntry,<FAR,PUBLIC,NODATA>,<>
  120. cBegin
  121. ifdef DEBUG
  122.         ;
  123.         ; if this module is not linked first the reserved parameter block
  124.         ; will not be initialized correctly, check for this and
  125.         ;
  126.         lea     ax,pLocalHeap
  127.         cmp     ax,6
  128.         je      RsrvPtrsOk
  129.  
  130. RsrvPtrsHosed:
  131.         int     3
  132.  
  133.         lea     ax,RsrvPtrsMsg
  134.         cCall   FatalAppExit,<0,cs,ax>
  135.         jmp     RsrvPtrsOk
  136.  
  137. RsrvPtrsMsg:
  138.         db      'RsrvPtrs hosed!',0
  139.  
  140. RsrvPtrsOk:
  141. endif
  142.     ;
  143.         ; Push frame for LibMain (hModule,cbHeap,lpszCmdLine)
  144.     ;
  145.     push    di
  146.     push    cx
  147.     push    es
  148.     push    si
  149.  
  150.         ;
  151.         ; Init the local heap (if one is declared in the .def file)
  152.         ;
  153.         jcxz no_heap
  154.  
  155.         cCall   LocalInit,<0,0,cx>
  156.  
  157. no_heap:
  158.         cCall   LibMain
  159. cEnd
  160.  
  161. ;--------------------------Exported-Routine-----------------------------;
  162. ;
  163. ;   WEP()
  164. ;
  165. ;   called when the DLL is unloaded, it is passed 1 WORD parameter that
  166. ;   is TRUE if the system is going down, or zero if the app is
  167. ;
  168. ;   WARNING:
  169. ;
  170. ;       This function is basicly useless, you cant can any kernel function
  171. ;       that may cause the LoadModule() code to be reentered..
  172. ;
  173. ;-----------------------------------------------------------------------;
  174.         assumes ds,nothing
  175.         assumes es,nothing
  176.  
  177. cProc   WEP,<FAR,PUBLIC,NODATA>,<>
  178.         ParmW  wparam
  179. cBegin
  180. cEnd
  181.  
  182. sEnd    CodeSeg
  183.  
  184.         end     LibEntry
  185.